var rivmsMenuActive = "rivms_Home";
function getMenuIndex(){
	return $("#rvimsMenuMain div").index($("#" + rivmsMenuActive));
}

function setTableCSS(tableId) {
	$("#" + tableId).addClass("ui-widget-content ui-corner-all listtable");
	$("#" + tableId +" thead tr").addClass("ui-widget-header ui-widget-content ui-corner-all");
	$("#" + tableId + " .bodytdbackground").removeClass("bodytdbackground");
	$("#" + tableId).each(function() {
		$(this).find("tbody tr:odd").addClass("bodytdbackground");
		$(this).find("tr").find("td:last").css("border-width", "0px");
	});
}

function clearInput(objIdorCss){
	$(objIdorCss + " input,select").val("");
}

function clickSelect(thistr){
	var objTr = $(thistr);
	if (objTr.hasClass("ui-state-active")) {
		objTr.removeClass("ui-state-active");
	} else {
		objTr.addClass("ui-state-active");
	}
}

function selectAllForList(listId){
	//$("#"+listId + " tbody").find("input[type='checkbox']").attr("checked",$("#"+listId+" thead input:checked").size() == 1);
	var checkboxes = $("#"+listId + " tbody").find("input[type='checkbox']");
	var bool = $("#"+listId+" thead input:checked").size() == 1;
	for (var i=0; i<checkboxes.length; i++) {
		checkboxes.get(i).checked = bool;
	}
}

function removeDuplicate(removedObjId, primaryObjId) {
	var prTrObjs = $("#" + primaryObjId + " tbody tr");
	var rmTrObjs = $("#" + removedObjId + " tbody");
	for (var i = 0; i < prTrObjs.size(); i++) {
		var trObjId = prTrObjs.eq(i).attr("id");
		if (rmTrObjs.has("#" + trObjId)) {
			rmTrObjs.find("#" + trObjId).html("");
			rmTrObjs.find("#" + trObjId).remove("tr");
		}
	}
	setTableCSS(removedObjId);
} 

function moveFromObjToObj(fromObjId,toObjId) {
	var moveObjs = $("#" + fromObjId).find(".ui-state-active");
	$("#" + toObjId + " tbody").append(moveObjs);
	setTableCSS(fromObjId);
	setTableCSS(toObjId);
}

function moveFromObjToObjAll(fromObjId,toObjId) {
	//$("#" + fromObjId + " tbody tr").addClass("ui-state-active");
	//moveFromObjToObj(fromObjId,toObjId);
	$("#" + toObjId + " tbody").append($("#" + fromObjId + " tbody tr"));
}

var dialogType = {warning:"warning",error:"error",tick:"tick",info:"info"};
function showMessageDialog(title,message,okFunction,type){
	$("#warningdialog").attr("title",title);
	$("#warningdialog .dialogpng").attr("src","imgs/dialog_" + type + ".png");
	$("#warningdialog .warningdialogmessage").html(message);
	if (okFunction != null) {
		$("#warningdialog").dialog({
			width: 328,
			resizable: false,
			modal: true,
			buttons: {
				"确定": function(){okFunction.call();$(this).dialog("close");},
				"取消": function(){$(this).dialog("close");}
			}
		});
	} else {
		$("#warningdialog").dialog({
			width: 328,
			resizable: false,
			modal: true,
			buttons: {
				"确定": function() {	$(this).dialog("close");}
			}
		});		
	}
}

/*
 * jui_pagination
 */
var rsc_jui_pag = {
	    go_to_page_title: '转到',
	    go_to_page_lable:'跳转到',
	    rows_per_page_title: '每页行数',
	    rows_per_page_lable: '每页行数',
	    current_page_label: '页',
	    total_pages_label: '共',
	    go_top_text: '&laquo;',
	    go_prev_text: '&larr;',
	    go_next_text: '&rarr;',
	    go_last_text: '&raquo;',
	    preferences_text: '&equiv;',
	    preferences_title: '设置分页',
	    preferences_close: '关闭',
	    pref_show_slider: '显示滑动条',
	    pref_show_goto_page: '显示跳转页',
	    pref_show_rows_per_page: '显示每页行数',
	    pref_show_rows_info: '显示行信息',
	    pref_show_nav_buttons: '显示导航图标'
	};

function setPagination(paginationId,totalPages,currentPage,pageSize,totalRows,callback) {
	$("#"+ paginationId).jui_pagination({
	    currentPage: currentPage,
	    visiblePageLinks: 5,
	    totalPages: totalPages, 
	    rowsPerPage:pageSize,
	    useSlider: false,
		sliderInsidePane: true,
        nav_pane_display_order: [
                                 'slider',
                                 'go_to_page',
                                 'back_buttons',
                                 'current_page_label',
                                 'current_page',
                                 'nav_items',
                                 'total_pages_label',
                                 'total_pages',
                                 'forward_buttons',
                                 'rows_per_page',
                                 'rows_info'
                             ],
	    disableSelectionNavPane: true,
	    showGoToPage:true,
	    showLabelTotalPages:true,
	    showTotalPages:true,
	    showRowsPerPage: true,
	    showRowsInfo:true,
	    
	    onChangePage: function(event, page_num) {
	        if(isNaN(page_num) || page_num <= 0) {
	        	showMessageDialog("提示","输入错误，请从新输入！",null,dialogType.info);
	        } else {
	        	callback(page_num,pageSize);
	        }
	       
	    },
	
		onSetRowsPerPage: function(event, rpp) {
			if(isNaN(rpp) || rpp <= 0) {
				showMessageDialog("提示","输入错误，请从新输入！",null,dialogType.info);
			} else {
				$(this).jui_pagination({
					rowsPerPage: rpp
				});
				callback(1,rpp);
			}
		},
		
	    onDisplay: function() {
			var showRowsInfo = $(this).jui_pagination('getOption', 'showRowsInfo');
			if(showRowsInfo) {
				var prefix = $(this).jui_pagination('getOption', 'nav_rows_info_id_prefix');
				$("#" + prefix + $(this).attr("id")).text('总行数: ' + totalRows);
			}
		}
	});
}
function ajaxFindVehicleCommon() {
	$.ajax({
		type:"post",
		url: "ajaxFindVehicleCommon.do",
		data:{platenum:$("#editPlateNum").val(),platetype:$("#editPlateType").val()},
		success:function(msg){
			$("#vehicleMessage").replaceWith(msg);
		}
	});
}

function ajaxFindCertificationCommon() {
	$.ajax({
		type:"post",
		url: "ajaxFindCertificationCommon.do",
		data:{certificatecode:$("#lstCertification").val()},
		success:function(msg){
			$("#certificationCommon").replaceWith(msg);
		}
	});
}